/**
 * Created by Administrator on 2017/9/4.
 */

    var banner = new Object();

    banner.init = function () {
        var studentBanners = [];
        var adminBanners = [];
        var object = new Object();
        object.img_url = resourcePath + "/static/global/images/v4/student_banner.jpg";
        // studentBanners.push(object);
        object = new Object();
        object.img_url = resourcePath + "/static/global/images/v4/banner_student.png";
        // studentBanners.push(object);
        object = new Object();
        object.img_url = resourcePath + "/static/global/images/v4/admin_banner.jpg";
        // adminBanners.push(object);
        object = new Object();
        object.img_url = resourcePath + "/static/global/images/v4/banner.png";
        // adminBanners.push(object);

        var params = {
            'domain': ""
        };
        $.ajax({
            url: appPath + "/domain/info",
            data: params,
            type: "post",
            dataType:"json",
            success: function(data) {
                var code = data.code;
                if("10000" == code){
                    var companySetting = data.result;
                    if(companySetting) {
                        var companyId = companySetting.companyId;
                        if(!companyId) {
                            return;
                        }
                        // 域名登录页companyId赋值
                        $("#companyId").val(companyId);
                        // 本地存储个性化信息
                        localStorage.setItem(companyId, JSON.stringify(companySetting));
                        if(companySetting) {
                            if(null != companySetting.cpStudentBanner && companySetting.cpStudentBanner.length > 0){
                                studentBanners = companySetting.cpStudentBanner;
                            }
                            if(null != companySetting.cpAdminBanner && companySetting.cpAdminBanner.length > 0){
                                adminBanners = companySetting.cpAdminBanner;
                            }
                            // 加载
                            initHearerLogo(companySetting);
                        }
                    }

                }
                if(studentBanners.length > 0){
                    // 加载学员首页banner轮播图
                    initStudentBanner(studentBanners);
                }if(adminBanners.length > 0){
                    // 加载管理员首页banner轮播图
                    initAdminBanner(adminBanners);
                }

            }
        });



        // 加载
        // initHearerLogo(companySetting);
    };

    // 函数自触发
    banner.init();


    function initStudentBanner (cpStudentBanner) {
        if(!cpStudentBanner) {
            return;
        }
        if($("#student_banner").length == 0) {
            return;
        }

        var img_url;
        var item = null;
        var innerhtml = "";
        for(var i=0; i< cpStudentBanner.length; i++) {
            item = cpStudentBanner[i];

            img_url = item.img_url;

            innerhtml += "<div class=\"swiper-slide\" style=\"background-image:url("+img_url+");background-size:cover\">";
            //innerhtml += "<div class=\"subtitle\" data-swiper-parallax=\"-200\">"+img_name+"</div>";
            innerhtml += "<div class=\"text\" data-swiper-parallax=\"-300\">";
            //innerhtml += "<p>"+img_desc+"</p>";
            innerhtml += "</div></div></div>";
        }
        $("#student_banner .swiper-wrapper ").html(innerhtml);

        var swiper_student_banner = new Swiper('#student_banner .swiper-container', {
            pagination: '.swiper-pagination',
            paginationClickable: true,
            autoplay: 4000
        });
    }

function initAdminBanner (cpAdminBanner) {
        debugger
    if(!cpAdminBanner) {
        return;
    }
    if($("#admin_banner").length == 0) {
        return;
    }

    var img_url;
    var item = null;
    var innerhtml = "";
    for(var i=0; i< cpAdminBanner.length; i++) {
        item = cpAdminBanner[i];

        img_url = item.img_url;

        innerhtml += "<div class=\"swiper-slide\" style=\"background-image:url("+img_url+");background-size:cover\">";
        //innerhtml += "<div class=\"subtitle\" data-swiper-parallax=\"-200\">"+img_name+"</div>";
        innerhtml += "<div class=\"text\" data-swiper-parallax=\"-300\">";
        //innerhtml += "<p>"+img_desc+"</p>";
        innerhtml += "</div></div></div>";
    }
    $("#admin_banner .swiper-wrapper ").html(innerhtml);

    var swiper_admin_banner = new Swiper('#admin_banner .swiper-container', {
        pagination: '.swiper-pagination',
        paginationClickable: true,
        autoplay: 4000
    });
}

function initHearerLogo(companySetting) {
    /*if(companySetting){
        $("#cpLogo").attr("src",companySetting.cpLogo);
        $("#cpLogo").attr("style","width: 100px;");
        var innerHtml = "";
        innerHtml += "<span style=\"color:#DDD;font-weight:100\">|</span>&nbsp;<span id=\"cpPlatName\" >"+companySetting.cpPlatName+"</span>";
        $("#cpLogo").append(innerHtml);
    }*/

}


